﻿@model PermissionMappingModel
@{               
    //page title
    ViewBag.Title = T("Admin.Configuration.ACL").Text;
}
@using (Html.BeginForm())
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
            @T("Admin.Configuration.ACL")
        </div>
        <div class="options">
            <input type="submit" name="save" class="k-button" value="@T("Admin.Common.Save")" />
        </div>
    </div>
    
    <table class="adminContent">
        <tr>
            <td>
                @if (Model.AvailablePermissions.Count == 0)
                {
                    <text>No permissions defined</text>
                }
                else if (Model.AvailableCustomerRoles.Count == 0)
                {
                    <text>No customer roles available</text>
                }
                else
                {
                    <script type="text/javascript">
                        $(document).ready(function () {            
                            @foreach (var cr in Model.AvailableCustomerRoles)
                            {
                                <text>
                                $('#selectall-@(cr.Id)').click(function () {
                                    $('.allow_@(cr.Id)').attr('checked', $(this).is(':checked')).change();
                                    });

                                </text>
                            }
                        });
                    </script>
                    <table class="tablestyle" cellspacing="0" rules="all" border="1" style="width: 100%;
                        border-collapse: collapse;">
                        <tbody>
                            <tr class="headerstyle">
                                <th scope="col">
                                    <strong>@T("Admin.Configuration.ACL.Permission")</strong>
                                </th>
                                @foreach (var cr in Model.AvailableCustomerRoles)
                                {
                                    <th scope="col">
                                        <strong>@cr.Name</strong>
                                        <input type="checkbox" id="selectall-@(cr.Id)" />
                                    </th>
                                }
                            </tr>
                            @{
                                bool altRow = true;
                            }
                            @foreach (var pr in Model.AvailablePermissions)
                            {
                                altRow = !altRow;
                                <tr class="@(altRow ? "altrowstyle" : "rowstyle")">
                                    <td>
                                        <span>@pr.Name</span>
                                    </td>
                                    @foreach (var cr in Model.AvailableCustomerRoles)
                                    {
                                        var allowed = Model.Allowed.ContainsKey(pr.SystemName) && Model.Allowed[pr.SystemName][cr.Id];
                                        <td>
                                            <input class="allow_@(cr.Id)" class="allow_@(cr.Id)" type="checkbox" value="@(pr.SystemName)" name="allow_@(cr.Id)" @(allowed ? " checked=checked" : null) />
                                        </td>
                                    }
                                </tr>
                            }
                        </tbody>
                    </table>
                }
            </td>
        </tr>
    </table>

}
